package com.h.blog.common.unit;

import com.h.blog.pojo.dataobject.BlogInfo;
import com.h.blog.pojo.dataobject.UserInfo;
import com.h.blog.pojo.request.AddBlogRequest;
import com.h.blog.pojo.request.UpdateBlogRequest;
import com.h.blog.pojo.response.BlogInfoResponse;
import com.h.blog.pojo.response.UserInfoResponse;
import org.springframework.beans.BeanUtils;

public class BeanTransUnits {
    public static BlogInfoResponse trans(BlogInfo blogInfo) {
        if (blogInfo == null) {
            return null;
        }
        BlogInfoResponse response = new BlogInfoResponse();
        BeanUtils.copyProperties(blogInfo, response);
        return response;
    }

    public static UserInfoResponse trans(UserInfo userInfo) {
        if (userInfo == null) {
            return null;
        }
        UserInfoResponse response = new UserInfoResponse();
        BeanUtils.copyProperties(userInfo,response);
        return response;
    }

    public static BlogInfo trans(AddBlogRequest request) {
        if(request == null) {
            return null;
        }
        BlogInfo blogInfo = new BlogInfo();
        BeanUtils.copyProperties(request,blogInfo);
        return blogInfo;
    }

    public static BlogInfo trans(UpdateBlogRequest request) {
        if(request == null) {
            return null;
        }
        BlogInfo blogInfo = new BlogInfo();
        BeanUtils.copyProperties(request,blogInfo);
        return blogInfo;
    }
}
